package com.agile.major.service.impl;

import com.agile.major.domain.BaseMajor;
import com.agile.major.domain.FreshGraduateBookAndTrain;
import com.agile.major.repository.BaseMajorRepository;
import com.agile.major.repository.FreshGraduateBookAndTrainRepository;
import com.agile.major.service.FreshGraduateBookAndTrainService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * Service Implementation for managing FreshGraduateBookAndTrain.
 */
@Service
@Transactional
public class FreshGraduateBookAndTrainServiceImpl implements FreshGraduateBookAndTrainService{

    private final Logger log = LoggerFactory.getLogger(FreshGraduateBookAndTrainServiceImpl.class);

    private final FreshGraduateBookAndTrainRepository freshGraduateBookAndTrainRepository;
    private BaseMajorRepository baseMajorRepository;
    public FreshGraduateBookAndTrainServiceImpl(
        FreshGraduateBookAndTrainRepository freshGraduateBookAndTrainRepository,
        BaseMajorRepository baseMajorRepository
    ) {
        this.freshGraduateBookAndTrainRepository = freshGraduateBookAndTrainRepository;
        this.baseMajorRepository=baseMajorRepository;
    }

    /**
     * Save a freshGraduateBookAndTrain.
     *
     * @param freshGraduateBookAndTrain the entity to save
     * @return the persisted entity
     */
    @Override
    public FreshGraduateBookAndTrain save(FreshGraduateBookAndTrain freshGraduateBookAndTrain) {
        log.debug("Request to save FreshGraduateBookAndTrain : {}", freshGraduateBookAndTrain);
        return freshGraduateBookAndTrainRepository.save(freshGraduateBookAndTrain);
    }

    /**
     *  Get all the freshGraduateBookAndTrains.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<FreshGraduateBookAndTrain> findAll(Pageable pageable) {
        log.debug("Request to get all FreshGraduateBookAndTrains");
        return freshGraduateBookAndTrainRepository.findAll(pageable);
    }

    /**
     *  Get one freshGraduateBookAndTrain by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public FreshGraduateBookAndTrain findOne(Long id) {
        log.debug("Request to get FreshGraduateBookAndTrain : {}", id);
        return freshGraduateBookAndTrainRepository.findOne(id);
    }

    /**
     *  Delete the  freshGraduateBookAndTrain by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete FreshGraduateBookAndTrain : {}", id);
        freshGraduateBookAndTrainRepository.delete(id);
    }

    @Override
    public Page<FreshGraduateBookAndTrain> getFreshGraduateBookAndTrainByMajor(Long id, Pageable pageable) {
        BaseMajor major = baseMajorRepository.findOne(id);
        if (major == null) {
            log.debug("Request to get RecruitStudent : {}", major);
        }
        return freshGraduateBookAndTrainRepository.findFreshGraduateBookAndTrainByBaseMajor(major,pageable);
    }
}
